<template>
    <van-nav-bar title="地址新增" left-text="返回" left-arrow @click-left="onClickLeft" />
    <van-address-edit :area-list="areaList" show-set-default show-search-result :search-result="searchResult"
        :area-columns-placeholder="['请选择', '请选择', '请选择']" @save="onSave" @change-detail="onChangeDetail" />
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { areaList } from '@vant/area-data'
import { addmap } from '../api/map'
import type { AddressEditInstance } from 'vant';
import router from '@/router';
import { useCommon } from '@/hooks/useCommon'
const {goback} = useCommon()
const onClickLeft = () => history.back();
const addressEditRef = ref<AddressEditInstance>();

addressEditRef.value?.setAddressDetail('');
const userid = localStorage.getItem('id')


const onSave = (AddressEditInstance: AddressEditInstance) => {
    addressEditRef.value = AddressEditInstance;
    const list = AddressEditInstance;
    console.log(list)

    addmap(
        userid,
        list.name,
        list.tel,
        list.province,
        list.city,
        list.county,
        list.addressDetail,
        list.isDefault
    ).then(result => {
        console.log(result)
        goback()
    })
};


</script>